﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsTest
{
    class DbHelper
    {
        private static readonly string connStr = "server=.;database=Blogs;uid=sa;pwd=123456";
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlCon = new SqlConnection(connStr);
            sqlCon.Open();
            DataTable table = new DataTable();
            SqlDataAdapter sqlData = new SqlDataAdapter(sql, sqlCon);
            sqlData.Fill(table);
            return table;
        }

        public static int AddOrEditOrDeleteSave(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(connStr);
            sqlConnection.Open();
            SqlCommand command = new SqlCommand(sql, sqlConnection);
            return command.ExecuteNonQuery();
        }
        public static SqlCommand AccountDatabase(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(connStr);
            sqlConnection.Open();
            SqlCommand command = new SqlCommand(sql, sqlConnection);
            return command;
        }
    }
}
